package com.zy.vod.controller;

import com.zy.commont.result.Result;
import com.zy.vod.service.VodService;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("vod")
@CrossOrigin
public class UploadVodController {

    @Autowired
    private VodService vodService;

    /*
    上传视频
     */
    @PostMapping("upload")
    public Result upload(MultipartFile file) {
        String videoSourceId = vodService.upload(file);
        return Result.ok().data("videoSourceId", videoSourceId);
    }

    /**
     * 根据视频ID获取播放凭证
     *
     * @return
     */
    @DeleteMapping("{videoSourceId}")
    public Result getVideoPlayAuth(@PathVariable String videoSourceId) {
        Boolean flag = vodService.deleteVodById(videoSourceId);
        if (flag) {
            return Result.ok();
        }
        return Result.error();
    }

    /**
     * 根据多个视频ID删除视频
     *
     * @return
     */
    @DeleteMapping("removeList")
    public Result removeList(
            @ApiParam(name = "videoIdList", value = "云端视频id", required = true)
            @RequestParam("videoIdList") List videoIdList) {
        Boolean flag = vodService.removeList(videoIdList);
        if (flag) {
            return Result.ok().message("删除成功");
        }
        return Result.error();


    }


}
